000100* FUNCTION : CBU-assert
000200* FILE : CBUP0002[.CBL]
000300 IDENTIFICATION DIVISION.
000400 PROGRAM-ID. CBUP0002.
000500 ENVIRONMENT DIVISION.
000600 CONFIGURATION SECTION.
000700 DATA DIVISION.
000800 WORKING-STORAGE SECTION.
000900
001000* COPYBOOKS
001100
001200*CALL INTERFACE FOR THE LOGGING PROGRAM
001300     COPY CBUC0004.
001400
001500* PROGRAM VARIABLES
001600
001700 01  CHECK-RESULT PIC X VALUE SPACE.
001800     88 FAILED VALUE "0".
001900     88 SUCCEED VALUE "1".
002000
002100 01  EXPECTED-VALUE       PIC X(1024)  VALUE SPACE.
002200 01  ACTUAL-VALUE         PIC X(1024)  VALUE SPACE.
002300 01  INTEGER-AS-A-STRING  PIC S9(15) .
002400 01  DEC-AS-A-STRING      PIC +9(9)V,9(5) .
002500
002600 01  DISPLAY-INTEGER1     PIC 9(9).
002700 01  DISPLAY-INTEGER2     PIC 9(9).
002800 01  DISPLAY-INTEGER3     PIC 9(9).
002900 01  DISPLAY-INTEGER4     PIC 9(9).
003000
003100
003200 LINKAGE SECTION.
003300     COPY CBUC0000.
003400     COPY CBUC0002.
003500 PROCEDURE DIVISION
003600       USING CBU-ctx CBU-ASSERT-CALL-INTERFACE.
003700
003800 mainline.
003900
004000* Logging ...
004100* EN101 Entering 'CBU-assert' for execution of %
004200     IF VERBOSE-MODE
004300        STRING "EN101" CBU-ASSERT-NAME
004400           DELIMITED BY SIZE INTO CBU-MESSAGE-TO-PRINT
004500        PERFORM CALLPRINT
004600     END-IF.
004700
004800*-------------------------------------------------------
004900     PERFORM RUN-add-assert-run.
005000*-------------------------------------------------------
005100     PERFORM CHECK-ACTUAL-VALUE.
005200*-------------------------------------------------------
005300     IF SUCCEED THEN PERFORM SUCCESS
005400                ELSE PERFORM FAILURE
005410     END-IF.
005500*-------------------------------------------------------
005600     SET CBU-ASSERT-NO-ERROR TO TRUE.
005700     MOVE SPACE TO CBU-ASSERT-MESSAGE.
005800
005900* Logging ...
006000* EN102 End of execution of 'CBU-assert' with no error
006100     IF VERBOSE-MODE
006200        MOVE
006300        "EN102" TO CBU-MESSAGE-TO-PRINT
006400        PERFORM CALLPRINT
006500     END-IF.
006600
006700     GOBACK.
006800
006900 RUN-add-assert-run.
007000
007100* Logging ...
007200* EN103 Running 'CBU-add-assert-run'
007300     IF VERBOSE-MODE
007400        MOVE "EN103" TO CBU-MESSAGE-TO-PRINT
007500        PERFORM CALLPRINT
007600     END-IF.
007700
007800     ADD 1 TO nb-assert-run (index-current-test).
007900
008000 CHECK-ACTUAL-VALUE.
008100
008200* CONVERT "EXPECTED" AND "ACTUAL" VALUES AS STRINGS IF NECESSARY
008300     EVALUATE TRUE
008400        WHEN CBU-ASSERT-INT
008500        PERFORM
008600           MOVE CBU-ASSERT-EXPECTED-INT
008700           TO   INTEGER-AS-A-STRING
008800           MOVE INTEGER-AS-A-STRING
008900           TO   EXPECTED-VALUE
009000           MOVE CBU-ASSERT-ACTUAL-INT
009100           TO   INTEGER-AS-A-STRING
009200           MOVE INTEGER-AS-A-STRING
009300           TO   ACTUAL-VALUE
009400        END-PERFORM
009500        WHEN CBU-ASSERT-DECIMAL
009600        PERFORM
009700           MOVE CBU-ASSERT-EXPECTED-DEC
009800           TO   DEC-AS-A-STRING
009900           MOVE DEC-AS-A-STRING
010000           TO   EXPECTED-VALUE
010100           MOVE CBU-ASSERT-ACTUAL-DEC
010200           TO   DEC-AS-A-STRING
010300           MOVE DEC-AS-A-STRING
010400           TO   ACTUAL-VALUE
010500        END-PERFORM
010600        WHEN CBU-ASSERT-STRING OR CBU-ASSERT-BOOLEAN
010700           MOVE CBU-ASSERT-EXPECTED-VAL
010800           TO   EXPECTED-VALUE
010900           MOVE CBU-ASSERT-ACTUAL-VAL
011000           TO   ACTUAL-VALUE
011100        WHEN OTHER
011200* WRONG DATA TYPE
011300* EN107 ASSERT-TYPE ("%") AND DATA-TYPE ("%")
011400* NOT CURRENTLY SUPPORTED"
011500           SET CBU-ASSERT-SEVERE TO TRUE
011600           STRING "EN107" CBU-ASSERT-TYPE "%" CBU-ASSERT-DATA-TYPE
011700              DELIMITED BY SIZE INTO CBU-MESSAGE-TO-PRINT
011800           PERFORM CALLPRINT
011900           MOVE CBU-COMPOSED-MSG TO CBU-ASSERT-MESSAGE
012000           PERFORM REPORT-ERROR
012100     END-EVALUATE.
012200
012300
012400* CHECK THE ASSERT
012500     EVALUATE TRUE
012600        WHEN CBU-ASSERT-EQUAL
012700         IF EXPECTED-VALUE   = ACTUAL-VALUE
012800            THEN SET SUCCEED TO TRUE
012900            ELSE SET FAILED  TO TRUE
013000         END-IF
013010
013100        WHEN CBU-ASSERT-NOT-EQUAL
013200         IF EXPECTED-VALUE   NOT = ACTUAL-VALUE
013300            THEN SET SUCCEED TO TRUE
013400            ELSE SET FAILED  TO TRUE
013410         END-IF
013500
013600        WHEN CBU-ASSERT-GT AND CBU-ASSERT-DECIMAL
013700         IF CBU-ASSERT-ACTUAL-DEC > CBU-ASSERT-EXPECTED-DEC
013800            THEN SET SUCCEED TO TRUE
013900            ELSE SET FAILED  TO TRUE
013910         END-IF
014000
014100        WHEN CBU-ASSERT-GE AND CBU-ASSERT-DECIMAL
014200         IF CBU-ASSERT-ACTUAL-DEC >= CBU-ASSERT-EXPECTED-DEC
014300            THEN SET SUCCEED TO TRUE
014400            ELSE SET FAILED  TO TRUE
014410         END-IF
014500
014600        WHEN CBU-ASSERT-LT AND CBU-ASSERT-DECIMAL
014700         IF CBU-ASSERT-ACTUAL-DEC < CBU-ASSERT-EXPECTED-DEC
014800            THEN SET SUCCEED TO TRUE
014900            ELSE SET FAILED  TO TRUE
014910         END-IF
015000
015100        WHEN CBU-ASSERT-LE AND CBU-ASSERT-DECIMAL
015200         IF CBU-ASSERT-ACTUAL-DEC <= CBU-ASSERT-EXPECTED-DEC
015300            THEN SET SUCCEED TO TRUE
015400            ELSE SET FAILED  TO TRUE
015410         END-IF
015500
015600        WHEN CBU-ASSERT-GT AND CBU-ASSERT-INT
015700         IF CBU-ASSERT-ACTUAL-INT > CBU-ASSERT-EXPECTED-INT
015800            THEN SET SUCCEED TO TRUE
015900            ELSE SET FAILED  TO TRUE
015910         END-IF
016000
016100        WHEN CBU-ASSERT-GE AND CBU-ASSERT-INT
016200         IF CBU-ASSERT-ACTUAL-INT >= CBU-ASSERT-EXPECTED-INT
016300            THEN SET SUCCEED TO TRUE
016400            ELSE SET FAILED  TO TRUE
016410         END-IF
016500
016600        WHEN CBU-ASSERT-LT AND CBU-ASSERT-INT
016700         IF CBU-ASSERT-ACTUAL-INT < CBU-ASSERT-EXPECTED-INT
016800            THEN SET SUCCEED TO TRUE
016900            ELSE SET FAILED  TO TRUE
016910         END-IF
017000
017100        WHEN CBU-ASSERT-LE AND CBU-ASSERT-INT
017200         IF CBU-ASSERT-ACTUAL-INT <= CBU-ASSERT-EXPECTED-INT
017300            THEN SET SUCCEED TO TRUE
017400            ELSE SET FAILED  TO TRUE
017410         END-IF
017500
017600        WHEN OTHER
017700* EN107 ASSERT-TYPE ("%") AND DATA-TYPE ("%")
017800* NOT CURRENTLY SUPPORTED"
017900           SET CBU-ASSERT-SEVERE TO TRUE
018000           STRING "EN107" CBU-ASSERT-TYPE "%" CBU-ASSERT-DATA-TYPE
018100              DELIMITED BY SIZE INTO CBU-MESSAGE-TO-PRINT
018200           PERFORM CALLPRINT
018300           MOVE CBU-COMPOSED-MSG TO CBU-ASSERT-MESSAGE
018400           PERFORM REPORT-ERROR
018500     END-EVALUATE.
018600
018700 FAILURE.
018800
018900*------------------------------------------------------------
019000     PERFORM RUN-add-assert-failed.
019100*------------------------------------------------------------
019200     PERFORM RUN-log-assert-failed.
019300*------------------------------------------------------------
019400
019500 RUN-add-assert-failed.
019600
019700     ADD 1 TO AssertFailureCount.
019800     ADD 1 TO nb-assert-failed (index-current-test).
019900
020000* Logging ...
020100*Running 'CBU-add-assert-failed' for SUITE # % and TEST # %
020200     IF VERBOSE-MODE
020300        MOVE index-current-suite TO DISPLAY-INTEGER1
020400        MOVE index-current-test  TO DISPLAY-INTEGER2
020500        STRING "EN104" DISPLAY-INTEGER1 "%" DISPLAY-INTEGER2
020600           DELIMITED BY SIZE INTO CBU-MESSAGE-TO-PRINT
020700        PERFORM CALLPRINT
020800     END-IF.
020900
021000 RUN-log-assert-failed.
021100
021200* Logging ...
021300* EN105 assertion '%' failure (expected: '%' but was '%')
021400     STRING "EN105" CBU-ASSERT-NAME "%" EXPECTED-VALUE "%"
021500       ACTUAL-VALUE DELIMITED BY SIZE INTO CBU-MESSAGE-TO-PRINT
021600     PERFORM CALLPRINT.
021700
021800 SUCCESS.
021900
022000*--------------------------------------------------------------
022100     PERFORM RUN-add-assert-succeed.
022200*--------------------------------------------------------------
022300     PERFORM RUN-log-assert-succeed.
022400*--------------------------------------------------------------
022500
022600 RUN-add-assert-succeed.
022700
022800     ADD 1 TO AssertTestCount.
022900     ADD 1 TO nb-assert-succeed (index-current-test).
023000
023100* Logging ...
023200* EN106 Running 'CBU-add-assert-succeed' for SUITE # %
023300     IF VERBOSE-MODE
023400        MOVE index-current-suite TO DISPLAY-INTEGER1
023500        MOVE index-current-test  TO DISPLAY-INTEGER2
023600        STRING "EN106" DISPLAY-INTEGER1 "%" DISPLAY-INTEGER2
023700           DELIMITED BY SIZE INTO CBU-MESSAGE-TO-PRINT
023800        PERFORM CALLPRINT
023900     END-IF.
024000
024100 RUN-log-assert-succeed.
024200
024300* CBU00050
024400* PROCEDURE DIVISION USING CBU-ctx CB050-AssertName.
024500*     INITIALIZE CB050-LogLine.
024600*     PERFORM VARYING CB050-CharCount3 FROM 19 BY -1
024700*        UNTIL CB050-AssertName (CB050-CharCount3:1) NOT = SPACE
024800*     END-PERFORM.
024900     CONTINUE.
025000
025100 CALLPRINT.
025200
025300* PRINT CURRENT LINE
025400     MOVE CBU-LANGUAGE TO CBU-MSG-LG
025500     CALL CBU-log-print USING CBU-LOG-PRINT-INTERFACE
025600* RESET DEFAULTS
025700     SET CBU-PRINT-A-LINE TO TRUE
025800     SET CBU-PRINT-ON-NEXT-LINE TO TRUE
025900     INITIALIZE CBU-MESSAGE-TO-PRINT.
026000
026100 REPORT-ERROR.
026200
026300* Logging ...
026400* EN108 End of Execution of 'CBU-assert' with Severe error
026500     IF STANDARD-LOG
026600        MOVE "EN108" TO CBU-MESSAGE-TO-PRINT
026700        PERFORM CALLPRINT
026800*        MOVE CBU-ASSERT-MESSAGE TO CBU-MESSAGE-TO-PRINT
026900*        PERFORM CALLPRINT
027000     END-IF.
027100
027200     GOBACK.
